
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.electronic_structure.cohp &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.electronic_structure.cohp</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.electronic_structure.cohp</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module defines classes to represent crystal orbital Hamilton</span>
<span class="sd">populations (COHP) and integrated COHP (ICOHP), but can also be used</span>
<span class="sd">for crystal orbital overlap populations (COOP).</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">sys</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span>

<span class="kn">from</span> <span class="nn">pymatgen.electronic_structure.core</span> <span class="kn">import</span> <span class="n">Spin</span><span class="p">,</span> <span class="n">Orbital</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.sites</span> <span class="kn">import</span> <span class="n">PeriodicSite</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.io.lmto</span> <span class="kn">import</span> <span class="n">LMTOCopl</span>
<span class="kn">from</span> <span class="nn">pymatgen.io.lobster</span> <span class="kn">import</span> <span class="n">Cohpcar</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.num</span> <span class="kn">import</span> <span class="n">round_to_sigfigs</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.coord</span> <span class="kn">import</span> <span class="n">get_linear_interpolated_value</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Marco Esters, Janine George&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2017, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;0.2&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Marco Esters, Janine George&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;esters@uoregon.edu, janine.george@uclouvain.be&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Dec 13, 2017&quot;</span>


<div class="viewcode-block" id="Cohp"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.Cohp">[docs]</a><span class="k">class</span> <span class="nc">Cohp</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Basic COHP object.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span> <span class="n">cohp</span><span class="p">,</span> <span class="n">are_coops</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">icohp</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            are_coops: Indicates whether this object describes COHPs or COOPs.</span>
<span class="sd">            efermi: Fermi energy.</span>
<span class="sd">            energies: A sequence of energies.</span>
<span class="sd">            cohp ({Spin: np.array}): representing the COHP for each spin.</span>
<span class="sd">            icohp ({Spin: np.array}): representing the ICOHP for each spin.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">are_coops</span> <span class="o">=</span> <span class="n">are_coops</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">=</span> <span class="n">efermi</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">energies</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span> <span class="o">=</span> <span class="n">cohp</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span> <span class="o">=</span> <span class="n">icohp</span>

    <span class="k">def</span> <span class="fm">__add__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds two COHP together. Checks that energy scales are the same.</span>
<span class="sd">        Otherwise, it raises a ValueError. It also adds ICOHP if present.</span>
<span class="sd">        If ICOHP is only present in one object, it displays a warning and</span>
<span class="sd">        will not add ICOHP.</span>

<span class="sd">        Args:</span>
<span class="sd">            other: Another COHP object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Sum of the two COHPs as a COHP object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">equal</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">energies</span><span class="p">)):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Energies of both COHP are not compatible.&quot;</span><span class="p">)</span>
        <span class="n">populations</span> <span class="o">=</span> <span class="p">{</span><span class="n">spin</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">populations</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">+</span> <span class="n">other</span><span class="o">.</span><span class="n">populations</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span>
                       <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span><span class="p">}</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">other</span><span class="o">.</span><span class="n">icohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">int_pop</span> <span class="o">=</span> <span class="p">{</span><span class="n">spin</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">+</span> <span class="n">other</span><span class="o">.</span><span class="n">icohp</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span>
                       <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span><span class="p">}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">other</span><span class="o">.</span><span class="n">icohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;One of the COHP objects does not contain &quot;</span>
                              <span class="s2">&quot;ICOHPs. Setting ICOHP to None.&quot;</span><span class="p">)</span>
            <span class="n">int_pop</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">return</span> <span class="n">Cohp</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">populations</span><span class="p">,</span> <span class="n">icohp</span><span class="o">=</span><span class="n">int_pop</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__str__</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a string that can be easily plotted (e.g. using gnuplot).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cohpstring</span> <span class="o">=</span> <span class="s2">&quot;COOP&quot;</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">are_coops</span> <span class="k">else</span> <span class="s2">&quot;COHP&quot;</span>
        <span class="n">header</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;Energy&quot;</span><span class="p">,</span> <span class="n">cohpstring</span> <span class="o">+</span> <span class="s2">&quot;Up&quot;</span><span class="p">]</span>
        <span class="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]]</span>
        <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span><span class="p">:</span>
            <span class="n">header</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cohpstring</span> <span class="o">+</span> <span class="s2">&quot;Down&quot;</span><span class="p">)</span>
            <span class="n">data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">])</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span><span class="p">:</span>
            <span class="n">header</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;I&quot;</span> <span class="o">+</span> <span class="n">cohpstring</span> <span class="o">+</span> <span class="s2">&quot;Up&quot;</span><span class="p">)</span>
            <span class="n">data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span><span class="p">:</span>
                <span class="n">header</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;I&quot;</span> <span class="o">+</span> <span class="n">cohpstring</span> <span class="o">+</span> <span class="s2">&quot;Down&quot;</span><span class="p">)</span>
                <span class="n">data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">])</span>
        <span class="n">formatheader</span> <span class="o">=</span> <span class="s2">&quot;#&quot;</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot;</span><span class="si">{:15s}</span><span class="s2">&quot;</span> <span class="k">for</span> <span class="n">__</span> <span class="ow">in</span> <span class="n">header</span><span class="p">])</span>
        <span class="n">formatdata</span> <span class="o">=</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot;</span><span class="si">{:.5f}</span><span class="s2">&quot;</span> <span class="k">for</span> <span class="n">__</span> <span class="ow">in</span> <span class="n">header</span><span class="p">])</span>
        <span class="n">stringarray</span> <span class="o">=</span> <span class="p">[</span><span class="n">formatheader</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">*</span><span class="n">header</span><span class="p">)]</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">__</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">):</span>
            <span class="n">stringarray</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">formatdata</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">]))</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">stringarray</span><span class="p">)</span>

<div class="viewcode-block" id="Cohp.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.Cohp.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation of COHP.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
             <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
             <span class="s2">&quot;are_coops&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">are_coops</span><span class="p">,</span>
             <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span>
             <span class="s2">&quot;energies&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span>
             <span class="s2">&quot;COHP&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">pops</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                      <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">pops</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">pops</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                          <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">pops</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="Cohp.get_cohp"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.Cohp.get_cohp">[docs]</a>    <span class="k">def</span> <span class="nf">get_cohp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">integrated</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the COHP or ICOHP for a particular spin.</span>

<span class="sd">        Args:</span>
<span class="sd">            spin: Spin. Can be parsed as spin object, integer (-1/1)</span>
<span class="sd">                or str (&quot;up&quot;/&quot;down&quot;)</span>
<span class="sd">            integrated: Return COHP (False) or ICOHP (True)</span>

<span class="sd">        Returns:</span>
<span class="sd">            Returns the CHOP or ICOHP for the input spin. If Spin is</span>
<span class="sd">            None and both spins are present, both spins will be returned</span>
<span class="sd">            as a dictionary.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">integrated</span><span class="p">:</span>
            <span class="n">populations</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">populations</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span>

        <span class="k">if</span> <span class="n">populations</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">spin</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">populations</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">spin</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">spin</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">s</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;up&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;down&quot;</span><span class="p">:</span> <span class="o">-</span><span class="mi">1</span><span class="p">}[</span><span class="n">spin</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span>
            <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">{</span><span class="n">spin</span><span class="p">:</span> <span class="n">populations</span><span class="p">[</span><span class="n">spin</span><span class="p">]}</span></div>

<div class="viewcode-block" id="Cohp.get_icohp"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.Cohp.get_icohp">[docs]</a>    <span class="k">def</span> <span class="nf">get_icohp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenient alternative to get the ICOHP for a particular spin.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cohp</span><span class="p">(</span><span class="n">spin</span><span class="o">=</span><span class="n">spin</span><span class="p">,</span> <span class="n">integrated</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div>

<div class="viewcode-block" id="Cohp.get_interpolated_value"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.Cohp.get_interpolated_value">[docs]</a>    <span class="k">def</span> <span class="nf">get_interpolated_value</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">energy</span><span class="p">,</span> <span class="n">integrated</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the COHP for a particular energy.</span>

<span class="sd">        Args:</span>
<span class="sd">            energy: Energy to return the COHP value for.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">inter</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">integrated</span><span class="p">:</span>
                <span class="n">inter</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_linear_interpolated_value</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                                                            <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span><span class="p">[</span><span class="n">spin</span><span class="p">],</span>
                                                            <span class="n">energy</span><span class="p">)</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">inter</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_linear_interpolated_value</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                                                            <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span><span class="p">[</span><span class="n">spin</span><span class="p">],</span>
                                                            <span class="n">energy</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;ICOHP is empty.&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">inter</span></div>

<div class="viewcode-block" id="Cohp.has_antibnd_states_below_efermi"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.Cohp.has_antibnd_states_below_efermi">[docs]</a>    <span class="k">def</span> <span class="nf">has_antibnd_states_below_efermi</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="mf">0.01</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns dict indicating if there are antibonding states below the Fermi level depending on the spin</span>
<span class="sd">            spin: Spin</span>
<span class="sd">            limit: -COHP smaller -limit will be considered.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;This method has not been tested on many examples. Check the parameter limit, pls!&quot;</span><span class="p">)</span>

        <span class="n">populations</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span>
        <span class="n">number_energies_below_efermi</span> <span class="o">=</span> <span class="nb">len</span><span class="p">([</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="k">if</span> <span class="n">x</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">])</span>

        <span class="k">if</span> <span class="n">populations</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">spin</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">dict_to_return</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">sp</span><span class="p">,</span> <span class="n">cohpvalues</span> <span class="ow">in</span> <span class="n">populations</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">cohpvalues</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">number_energies_below_efermi</span><span class="p">]))</span> <span class="o">&gt;</span> <span class="n">limit</span><span class="p">:</span>
                    <span class="n">dict_to_return</span><span class="p">[</span><span class="n">sp</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">dict_to_return</span><span class="p">[</span><span class="n">sp</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">dict_to_return</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">spin</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
                <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">spin</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                <span class="n">s</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;up&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;down&quot;</span><span class="p">:</span> <span class="o">-</span><span class="mi">1</span><span class="p">}[</span><span class="n">spin</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span>
                <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
            <span class="k">if</span> <span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">populations</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="n">number_energies_below_efermi</span><span class="p">]))</span> <span class="o">&gt;</span> <span class="n">limit</span><span class="p">:</span>
                <span class="n">dict_to_return</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">dict_to_return</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="k">return</span> <span class="n">dict_to_return</span></div>

<div class="viewcode-block" id="Cohp.from_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.Cohp.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a COHP object from a dict representation of the COHP.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s2">&quot;ICOHP&quot;</span> <span class="ow">in</span> <span class="n">d</span><span class="p">:</span>
            <span class="n">icohp</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">key</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
                     <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">icohp</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">return</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;efermi&quot;</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;energies&quot;</span><span class="p">],</span>
                    <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">key</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
                     <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;COHP&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()},</span>
                    <span class="n">icohp</span><span class="o">=</span><span class="n">icohp</span><span class="p">,</span> <span class="n">are_coops</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;are_coops&quot;</span><span class="p">])</span></div></div>


<div class="viewcode-block" id="CompleteCohp"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.CompleteCohp">[docs]</a><span class="k">class</span> <span class="nc">CompleteCohp</span><span class="p">(</span><span class="n">Cohp</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A wrapper class that defines an average COHP, and individual COHPs.</span>

<span class="sd">    .. attribute: are_coops</span>

<span class="sd">         Indicates whether the object is of COOPs or COHPs.</span>

<span class="sd">    .. attribute: efermi</span>

<span class="sd">         Fermi energy</span>

<span class="sd">    .. attribute: energies</span>

<span class="sd">         Sequence of energies</span>

<span class="sd">    .. attribute: structure</span>

<span class="sd">         Structure associated with the COHPs.</span>

<span class="sd">    .. attribute: cohp, icohp</span>

<span class="sd">         The average COHP/ICOHP.</span>

<span class="sd">    .. attribute: all_cohps</span>

<span class="sd">         A dict of COHPs for individual bonds of the form {label: COHP}</span>

<span class="sd">    .. attribute: orb_res_cohp</span>

<span class="sd">        Orbital-resolved COHPs.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">avg_cohp</span><span class="p">,</span> <span class="n">cohp_dict</span><span class="p">,</span> <span class="n">bonds</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">are_coops</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">orb_res_cohp</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            structure: Structure assosciated with this COHP.</span>
<span class="sd">            avg_cohp: The average cohp as a COHP object.</span>
<span class="sd">            cohps: A dict of COHP objects for individual bonds of the form</span>
<span class="sd">                {label: COHP}</span>
<span class="sd">            bonds: A dict containing information on the bonds of the form</span>
<span class="sd">                {label: {key: val}}. The key-val pair can be any information</span>
<span class="sd">                the user wants to put in, but typically contains the sites,</span>
<span class="sd">                the bond length, and the number of bonds. If nothing is</span>
<span class="sd">                supplied, it will default to an empty dict.</span>
<span class="sd">            are_coops: indicates whether the Cohp objects are COHPs or COOPs.</span>
<span class="sd">                Defauls to False for COHPs.</span>
<span class="sd">            orb_res_cohp: Orbital-resolved COHPs.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">avg_cohp</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="n">avg_cohp</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">avg_cohp</span><span class="o">.</span><span class="n">cohp</span><span class="p">,</span>
                         <span class="n">are_coops</span><span class="o">=</span><span class="n">are_coops</span><span class="p">,</span> <span class="n">icohp</span><span class="o">=</span><span class="n">avg_cohp</span><span class="o">.</span><span class="n">icohp</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">are_coops</span> <span class="o">=</span> <span class="n">are_coops</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">all_cohps</span> <span class="o">=</span> <span class="n">cohp_dict</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span> <span class="o">=</span> <span class="n">orb_res_cohp</span>
        <span class="k">if</span> <span class="n">bonds</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span> <span class="o">=</span> <span class="p">{</span><span class="n">label</span><span class="p">:</span> <span class="p">{}</span> <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_cohps</span><span class="o">.</span><span class="n">keys</span><span class="p">()}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span> <span class="o">=</span> <span class="n">bonds</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">are_coops</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;Complete COOPs for &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
        <span class="k">return</span> <span class="s2">&quot;Complete COHPs for &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>

<div class="viewcode-block" id="CompleteCohp.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.CompleteCohp.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation of CompleteCohp.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
             <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
             <span class="s2">&quot;are_coops&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">are_coops</span><span class="p">,</span>
             <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span>
             <span class="s2">&quot;structure&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
             <span class="s2">&quot;energies&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span>
             <span class="s2">&quot;COHP&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;average&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">pops</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                                  <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">pops</span> <span class="ow">in</span>
                                  <span class="bp">self</span><span class="o">.</span><span class="n">cohp</span><span class="o">.</span><span class="n">items</span><span class="p">()}}}</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;average&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">pops</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                                      <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">pops</span> <span class="ow">in</span>
                                      <span class="bp">self</span><span class="o">.</span><span class="n">icohp</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span>

        <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_cohps</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;COHP&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">label</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">pops</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                                      <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">pops</span> <span class="ow">in</span>
                                      <span class="bp">self</span><span class="o">.</span><span class="n">all_cohps</span><span class="p">[</span><span class="n">label</span><span class="p">]</span><span class="o">.</span><span class="n">cohp</span><span class="o">.</span><span class="n">items</span><span class="p">()}})</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_cohps</span><span class="p">[</span><span class="n">label</span><span class="p">]</span><span class="o">.</span><span class="n">icohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="s2">&quot;ICOHP&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                    <span class="n">d</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">label</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">pops</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                                          <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">pops</span> <span class="ow">in</span>
                                          <span class="bp">self</span><span class="o">.</span><span class="n">all_cohps</span><span class="p">[</span><span class="n">label</span><span class="p">]</span><span class="o">.</span><span class="n">icohp</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">d</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">label</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">pops</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                                               <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">pops</span> <span class="ow">in</span>
                                               <span class="bp">self</span><span class="o">.</span><span class="n">all_cohps</span><span class="p">[</span><span class="n">label</span><span class="p">]</span><span class="o">.</span><span class="n">icohp</span><span class="o">.</span><span class="n">items</span><span class="p">()}})</span>
        <span class="k">if</span> <span class="kc">False</span> <span class="ow">in</span> <span class="p">[</span><span class="n">bond_dict</span> <span class="o">==</span> <span class="p">{}</span> <span class="k">for</span> <span class="n">bond_dict</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">values</span><span class="p">()]:</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;bonds&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">bond</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;length&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">[</span><span class="n">bond</span><span class="p">][</span><span class="s2">&quot;length&quot;</span><span class="p">],</span>
                                 <span class="s2">&quot;sites&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">for</span> <span class="n">site</span>
                                           <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">[</span><span class="n">bond</span><span class="p">][</span><span class="s2">&quot;sites&quot;</span><span class="p">]]}</span>
                          <span class="k">for</span> <span class="n">bond</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">}</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span><span class="p">:</span>
            <span class="n">orb_dict</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span><span class="p">:</span>
                <span class="n">orb_dict</span><span class="p">[</span><span class="n">label</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="k">for</span> <span class="n">orbs</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]:</span>
                    <span class="n">cohp</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">pops</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">pops</span> <span class="ow">in</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orbs</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
                    <span class="n">orb_dict</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orbs</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;COHP&quot;</span><span class="p">:</span> <span class="n">cohp</span><span class="p">}</span>
                    <span class="n">icohp</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">pops</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">pops</span> <span class="ow">in</span>
                             <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orbs</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
                    <span class="n">orb_dict</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orbs</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">icohp</span>
                    <span class="n">orbitals</span> <span class="o">=</span> <span class="p">[[</span><span class="n">orb</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">orb</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="k">for</span> <span class="n">orb</span> <span class="ow">in</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orbs</span><span class="p">][</span><span class="s2">&quot;orbitals&quot;</span><span class="p">]]</span>
                    <span class="n">orb_dict</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orbs</span><span class="p">][</span><span class="s2">&quot;orbitals&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">orbitals</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;orb_res_cohp&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">orb_dict</span>

        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="CompleteCohp.get_cohp_by_label"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.CompleteCohp.get_cohp_by_label">[docs]</a>    <span class="k">def</span> <span class="nf">get_cohp_by_label</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get specific COHP object.</span>

<span class="sd">        Args:</span>
<span class="sd">            label: string (for newer Lobster versions: a number)</span>

<span class="sd">        Returns:</span>
<span class="sd">            Returns the COHP object to simplify plotting</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">label</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;average&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">efermi</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                        <span class="n">cohp</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">cohp</span><span class="p">,</span> <span class="n">are_coops</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">are_coops</span><span class="p">,</span> <span class="n">icohp</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">icohp</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">efermi</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                    <span class="n">cohp</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">all_cohps</span><span class="p">[</span><span class="n">label</span><span class="p">]</span><span class="o">.</span><span class="n">get_cohp</span><span class="p">(</span><span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">integrated</span><span class="o">=</span><span class="kc">False</span><span class="p">),</span>
                    <span class="n">are_coops</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">are_coops</span><span class="p">,</span>
                    <span class="n">icohp</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">all_cohps</span><span class="p">[</span><span class="n">label</span><span class="p">]</span><span class="o">.</span><span class="n">get_icohp</span><span class="p">(</span><span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">))</span></div>

<div class="viewcode-block" id="CompleteCohp.get_summed_cohp_by_label_list"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.CompleteCohp.get_summed_cohp_by_label_list">[docs]</a>    <span class="k">def</span> <span class="nf">get_summed_cohp_by_label_list</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label_list</span><span class="p">,</span> <span class="n">divisor</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a COHP object that includes a summed COHP divided by divisor</span>

<span class="sd">        Args:</span>
<span class="sd">            label_list: list of labels for the COHP that should be included in the summed cohp</span>
<span class="sd">            divisor: float/int, the summed cohp will be divided by this divisor</span>
<span class="sd">        Returns:</span>
<span class="sd">            Returns a COHP object including a summed COHP</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># check if cohps are spinpolarized or not</span>
        <span class="n">first_cohpobject</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cohp_by_label</span><span class="p">(</span><span class="n">label_list</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">summed_cohp</span> <span class="o">=</span> <span class="n">first_cohpobject</span><span class="o">.</span><span class="n">cohp</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">summed_icohp</span> <span class="o">=</span> <span class="n">first_cohpobject</span><span class="o">.</span><span class="n">icohp</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">label_list</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
            <span class="n">cohp_here</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cohp_by_label</span><span class="p">(</span><span class="n">label</span><span class="p">)</span>
            <span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">],</span> <span class="n">cohp_here</span><span class="o">.</span><span class="n">cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="n">summed_cohp</span><span class="p">:</span>
                <span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">],</span> <span class="n">cohp_here</span><span class="o">.</span><span class="n">cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">],</span> <span class="n">cohp_here</span><span class="o">.</span><span class="n">icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="n">summed_icohp</span><span class="p">:</span>
                <span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">],</span> <span class="n">cohp_here</span><span class="o">.</span><span class="n">icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

        <span class="n">divided_cohp</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">divided_icohp</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">divided_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">divide</span><span class="p">(</span><span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">],</span> <span class="n">divisor</span><span class="p">)</span>
        <span class="n">divided_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">divide</span><span class="p">(</span><span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">],</span> <span class="n">divisor</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="n">summed_cohp</span><span class="p">:</span>
            <span class="n">divided_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">divide</span><span class="p">(</span><span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">],</span> <span class="n">divisor</span><span class="p">)</span>
            <span class="n">divided_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">divide</span><span class="p">(</span><span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">],</span> <span class="n">divisor</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">efermi</span><span class="o">=</span><span class="n">first_cohpobject</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="o">=</span><span class="n">first_cohpobject</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">cohp</span><span class="o">=</span><span class="n">divided_cohp</span><span class="p">,</span>
                    <span class="n">are_coops</span><span class="o">=</span><span class="n">first_cohpobject</span><span class="o">.</span><span class="n">are_coops</span><span class="p">,</span>
                    <span class="n">icohp</span><span class="o">=</span><span class="n">divided_icohp</span><span class="p">)</span></div>

<div class="viewcode-block" id="CompleteCohp.get_summed_cohp_by_label_and_orbital_list"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.CompleteCohp.get_summed_cohp_by_label_and_orbital_list">[docs]</a>    <span class="k">def</span> <span class="nf">get_summed_cohp_by_label_and_orbital_list</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label_list</span><span class="p">,</span> <span class="n">orbital_list</span><span class="p">,</span> <span class="n">divisor</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a COHP object that includes a summed COHP divided by divisor</span>

<span class="sd">        Args:</span>
<span class="sd">            label_list: list of labels for the COHP that should be included in the summed cohp</span>
<span class="sd">            orbital_list: list of orbitals for the COHPs that should be included in the summed cohp (same order as</span>
<span class="sd">                label_list)</span>
<span class="sd">            divisor: float/int, the summed cohp will be divided by this divisor</span>
<span class="sd">        Returns:</span>
<span class="sd">            Returns a COHP object including a summed COHP</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># check length of label_list and orbital_list:</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">len</span><span class="p">(</span><span class="n">label_list</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">orbital_list</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;label_list and orbital_list don&#39;t have the same length!&quot;</span><span class="p">)</span>
        <span class="c1"># check if cohps are spinpolarized or not</span>
        <span class="n">first_cohpobject</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_orbital_resolved_cohp</span><span class="p">(</span><span class="n">label_list</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">orbital_list</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">summed_cohp</span> <span class="o">=</span> <span class="n">first_cohpobject</span><span class="o">.</span><span class="n">cohp</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">summed_icohp</span> <span class="o">=</span> <span class="n">first_cohpobject</span><span class="o">.</span><span class="n">icohp</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">ilabel</span><span class="p">,</span> <span class="n">label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">label_list</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="mi">1</span><span class="p">):</span>
            <span class="n">cohp_here</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_orbital_resolved_cohp</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">orbital_list</span><span class="p">[</span><span class="n">ilabel</span><span class="p">])</span>
            <span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">],</span> <span class="n">cohp_here</span><span class="o">.</span><span class="n">cohp</span><span class="o">.</span><span class="n">copy</span><span class="p">()[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="n">summed_cohp</span><span class="p">:</span>
                <span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">],</span> <span class="n">cohp_here</span><span class="o">.</span><span class="n">cohp</span><span class="o">.</span><span class="n">copy</span><span class="p">()[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">],</span> <span class="n">cohp_here</span><span class="o">.</span><span class="n">icohp</span><span class="o">.</span><span class="n">copy</span><span class="p">()[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="n">summed_icohp</span><span class="p">:</span>
                <span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">],</span> <span class="n">cohp_here</span><span class="o">.</span><span class="n">icohp</span><span class="o">.</span><span class="n">copy</span><span class="p">()[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

        <span class="n">divided_cohp</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">divided_icohp</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">divided_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">divide</span><span class="p">(</span><span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">],</span> <span class="n">divisor</span><span class="p">)</span>
        <span class="n">divided_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">divide</span><span class="p">(</span><span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">],</span> <span class="n">divisor</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="n">summed_cohp</span><span class="p">:</span>
            <span class="n">divided_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">divide</span><span class="p">(</span><span class="n">summed_cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">],</span> <span class="n">divisor</span><span class="p">)</span>
            <span class="n">divided_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">divide</span><span class="p">(</span><span class="n">summed_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">],</span> <span class="n">divisor</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">efermi</span><span class="o">=</span><span class="n">first_cohpobject</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="o">=</span><span class="n">first_cohpobject</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">cohp</span><span class="o">=</span><span class="n">divided_cohp</span><span class="p">,</span>
                    <span class="n">are_coops</span><span class="o">=</span><span class="n">first_cohpobject</span><span class="o">.</span><span class="n">are_coops</span><span class="p">,</span>
                    <span class="n">icohp</span><span class="o">=</span><span class="n">divided_icohp</span><span class="p">)</span></div>

<div class="viewcode-block" id="CompleteCohp.get_orbital_resolved_cohp"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.CompleteCohp.get_orbital_resolved_cohp">[docs]</a>    <span class="k">def</span> <span class="nf">get_orbital_resolved_cohp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">orbitals</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get orbital-resolved COHP.</span>

<span class="sd">        Args:</span>
<span class="sd">            label: bond label (Lobster: labels as in ICOHPLIST/ICOOPLIST.lobster).</span>

<span class="sd">            orbitals: The orbitals as a label, or list or tuple of the form</span>
<span class="sd">                [(n1, orbital1), (n2, orbital2)]. Orbitals can either be str,</span>
<span class="sd">                int, or Orbital.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A Cohp object if CompleteCohp contains orbital-resolved cohp,</span>
<span class="sd">            or None if it doesn&#39;t.</span>

<span class="sd">        Note: It currently assumes that orbitals are str if they aren&#39;t the</span>
<span class="sd">            other valid types. This is not ideal, but the easiest way to</span>
<span class="sd">            avoid unicode issues between python 2 and python 3.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">orbitals</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
            <span class="n">cohp_orbs</span> <span class="o">=</span> <span class="p">[</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;orbitals&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span>
                         <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">()]</span>
            <span class="n">orbs</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">orbital</span> <span class="ow">in</span> <span class="n">orbitals</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="nb">int</span><span class="p">):</span>
                    <span class="n">orbs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">tuple</span><span class="p">((</span><span class="n">orbital</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">Orbital</span><span class="p">(</span><span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">]))))</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">Orbital</span><span class="p">):</span>
                    <span class="n">orbs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">tuple</span><span class="p">((</span><span class="n">orbital</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">])))</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="nb">str</span><span class="p">):</span>
                    <span class="n">orbs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">tuple</span><span class="p">((</span><span class="n">orbital</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">Orbital</span><span class="p">[</span><span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">]])))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;Orbital must be str, int, or Orbital.&quot;</span><span class="p">)</span>
            <span class="n">orb_index</span> <span class="o">=</span> <span class="n">cohp_orbs</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">orbs</span><span class="p">)</span>
            <span class="n">orb_label</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">())[</span><span class="n">orb_index</span><span class="p">]</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">orbitals</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">orb_label</span> <span class="o">=</span> <span class="n">orbitals</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;Orbitals must be str, list, or tuple.&quot;</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">icohp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orb_label</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="n">icohp</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">return</span> <span class="n">Cohp</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orb_label</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">],</span>
                    <span class="n">icohp</span><span class="o">=</span><span class="n">icohp</span><span class="p">,</span> <span class="n">are_coops</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">are_coops</span><span class="p">)</span></div>

<div class="viewcode-block" id="CompleteCohp.from_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.CompleteCohp.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns CompleteCohp object from dict representation.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cohp_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">efermi</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;efermi&quot;</span><span class="p">]</span>
        <span class="n">energies</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;energies&quot;</span><span class="p">]</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;structure&quot;</span><span class="p">])</span>
        <span class="k">if</span> <span class="s2">&quot;bonds&quot;</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">bonds</span> <span class="o">=</span> <span class="p">{</span><span class="n">bond</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;length&quot;</span><span class="p">:</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;bonds&quot;</span><span class="p">][</span><span class="n">bond</span><span class="p">][</span><span class="s2">&quot;length&quot;</span><span class="p">],</span>
                            <span class="s2">&quot;sites&quot;</span><span class="p">:</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">PeriodicSite</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">site</span><span class="p">)</span>
                                           <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;bonds&quot;</span><span class="p">][</span><span class="n">bond</span><span class="p">][</span><span class="s2">&quot;sites&quot;</span><span class="p">])}</span>
                     <span class="k">for</span> <span class="n">bond</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;bonds&quot;</span><span class="p">]}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">bonds</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;COHP&quot;</span><span class="p">]:</span>
            <span class="n">cohp</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;COHP&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">][</span><span class="n">spin</span><span class="p">])</span>
                    <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;COHP&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">]}</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">icohp</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">][</span><span class="n">spin</span><span class="p">])</span>
                         <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">]}</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="n">icohp</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">if</span> <span class="n">label</span> <span class="o">==</span> <span class="s2">&quot;average&quot;</span><span class="p">:</span>
                <span class="n">avg_cohp</span> <span class="o">=</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span> <span class="n">cohp</span><span class="p">,</span> <span class="n">icohp</span><span class="o">=</span><span class="n">icohp</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">cohp_dict</span><span class="p">[</span><span class="n">label</span><span class="p">]</span> <span class="o">=</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span> <span class="n">cohp</span><span class="p">,</span> <span class="n">icohp</span><span class="o">=</span><span class="n">icohp</span><span class="p">)</span>

        <span class="k">if</span> <span class="s2">&quot;orb_res_cohp&quot;</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">orb_cohp</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;orb_res_cohp&quot;</span><span class="p">]:</span>
                <span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="k">for</span> <span class="n">orb</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;orb_res_cohp&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">]:</span>
                    <span class="n">cohp</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;orb_res_cohp&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">][</span><span class="n">s</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
                            <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;orb_res_cohp&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">]}</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">icohp</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;orb_res_cohp&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">][</span><span class="n">s</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
                                 <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;orb_res_cohp&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]}</span>
                    <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                        <span class="n">icohp</span> <span class="o">=</span> <span class="kc">None</span>
                    <span class="n">orbitals</span> <span class="o">=</span> <span class="p">[</span><span class="nb">tuple</span><span class="p">((</span><span class="nb">int</span><span class="p">(</span><span class="n">o</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">Orbital</span><span class="p">[</span><span class="n">o</span><span class="p">[</span><span class="mi">1</span><span class="p">]]))</span> <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span>
                                <span class="n">d</span><span class="p">[</span><span class="s2">&quot;orb_res_cohp&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">][</span><span class="s2">&quot;orbitals&quot;</span><span class="p">]]</span>
                    <span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;COHP&quot;</span><span class="p">:</span> <span class="n">cohp</span><span class="p">,</span> <span class="s2">&quot;ICOHP&quot;</span><span class="p">:</span> <span class="n">icohp</span><span class="p">,</span>
                                            <span class="s2">&quot;orbitals&quot;</span><span class="p">:</span> <span class="n">orbitals</span><span class="p">}</span>
                <span class="c1"># If no total COHPs are present, calculate the total</span>
                <span class="c1"># COHPs from the single-orbital populations. Total COHPs</span>
                <span class="c1"># may not be present when the cohpgenerator keyword is used</span>
                <span class="c1"># in LOBSTER versions 2.2.0 and earlier.</span>
                <span class="k">if</span> <span class="n">label</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;COHP&quot;</span><span class="p">]</span> <span class="ow">or</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;COHP&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">cohp</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
                        <span class="p">[</span><span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">][</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span>
                         <span class="k">for</span> <span class="n">orb</span> <span class="ow">in</span> <span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]]),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)}</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">cohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">][</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span>
                                                           <span class="k">for</span> <span class="n">orb</span> <span class="ow">in</span> <span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]]),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
                    <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                        <span class="k">pass</span>

                <span class="n">orb_res_icohp</span> <span class="o">=</span> <span class="kc">None</span> <span class="ow">in</span> <span class="p">[</span><span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">orb</span> <span class="ow">in</span> <span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]]</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">label</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span> <span class="ow">or</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">and</span> <span class="n">orb_res_icohp</span><span class="p">:</span>
                    <span class="n">icohp</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">][</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span>
                                                       <span class="k">for</span> <span class="n">orb</span> <span class="ow">in</span> <span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]]),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)}</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orb</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">][</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span>
                                                            <span class="k">for</span> <span class="n">orb</span> <span class="ow">in</span> <span class="n">orb_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]]),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
                    <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                        <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">orb_cohp</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="s2">&quot;average&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;COHP&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="c1"># calculate average</span>
            <span class="n">cohp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
                             <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;COHP&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">()])</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">icohp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
                                  <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">()])</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="n">icohp</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">avg_cohp</span> <span class="o">=</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span> <span class="n">cohp</span><span class="p">,</span> <span class="n">icohp</span><span class="o">=</span><span class="n">icohp</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">CompleteCohp</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">avg_cohp</span><span class="p">,</span> <span class="n">cohp_dict</span><span class="p">,</span> <span class="n">bonds</span><span class="o">=</span><span class="n">bonds</span><span class="p">,</span>
                            <span class="n">are_coops</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;are_coops&quot;</span><span class="p">],</span> <span class="n">orb_res_cohp</span><span class="o">=</span><span class="n">orb_cohp</span><span class="p">)</span></div>

<div class="viewcode-block" id="CompleteCohp.from_file"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.CompleteCohp.from_file">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">fmt</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                  <span class="n">structure_file</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">are_coops</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Creates a CompleteCohp object from an output file of a COHP</span>
<span class="sd">        calculation. Valid formats are either LMTO (for the Stuttgart</span>
<span class="sd">        LMTO-ASA code) or LOBSTER (for the LOBSTER code).</span>

<span class="sd">        Args:</span>
<span class="sd">            cohp_file: Name of the COHP output file. Defaults to COPL</span>
<span class="sd">                for LMTO and COHPCAR.lobster/COOPCAR.lobster for LOBSTER.</span>

<span class="sd">            are_coops: Indicates whether the populations are COOPs or</span>
<span class="sd">                COHPs. Defaults to False for COHPs.</span>

<span class="sd">            fmt: A string for the code that was used to calculate</span>
<span class="sd">                the COHPs so that the output file can be handled</span>
<span class="sd">                correctly. Can take the values &quot;LMTO&quot; or &quot;LOBSTER&quot;.</span>

<span class="sd">            structure_file: Name of the file containing the structure.</span>
<span class="sd">                If no file name is given, use CTRL for LMTO and POSCAR</span>
<span class="sd">                for LOBSTER.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A CompleteCohp object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">fmt</span> <span class="o">=</span> <span class="n">fmt</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">fmt</span> <span class="o">==</span> <span class="s2">&quot;LMTO&quot;</span><span class="p">:</span>
            <span class="c1"># LMTO COOPs and orbital-resolved COHP cannot be handled yet.</span>
            <span class="n">are_coops</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="n">orb_res_cohp</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">if</span> <span class="n">structure_file</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">structure_file</span> <span class="o">=</span> <span class="s2">&quot;CTRL&quot;</span>
            <span class="k">if</span> <span class="n">filename</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">filename</span> <span class="o">=</span> <span class="s2">&quot;COPL&quot;</span>
            <span class="n">cohp_file</span> <span class="o">=</span> <span class="n">LMTOCopl</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">filename</span><span class="p">,</span> <span class="n">to_eV</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">fmt</span> <span class="o">==</span> <span class="s2">&quot;LOBSTER&quot;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">structure_file</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">structure_file</span> <span class="o">=</span> <span class="s2">&quot;POSCAR&quot;</span>
            <span class="k">if</span> <span class="n">filename</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">filename</span> <span class="o">=</span> <span class="s2">&quot;COOPCAR.lobster&quot;</span> <span class="k">if</span> <span class="n">are_coops</span> \
                    <span class="k">else</span> <span class="s2">&quot;COHPCAR.lobster&quot;</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                <span class="s2">&quot;The bond labels are currently consistent with ICOHPLIST.lobster/ICOOPLIST.lobster, not with &quot;</span>
                <span class="s2">&quot;COHPCAR.lobster/COOPCAR.lobster. Please be aware!&quot;</span><span class="p">)</span>
            <span class="n">cohp_file</span> <span class="o">=</span> <span class="n">Cohpcar</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">filename</span><span class="p">,</span> <span class="n">are_coops</span><span class="o">=</span><span class="n">are_coops</span><span class="p">)</span>
            <span class="n">orb_res_cohp</span> <span class="o">=</span> <span class="n">cohp_file</span><span class="o">.</span><span class="n">orb_res_cohp</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Unknown format </span><span class="si">%s</span><span class="s2">. Valid formats are LMTO &quot;</span>
                             <span class="s2">&quot;and LOBSTER.&quot;</span> <span class="o">%</span> <span class="n">fmt</span><span class="p">)</span>

        <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">structure_file</span><span class="p">)</span>
        <span class="n">efermi</span> <span class="o">=</span> <span class="n">cohp_file</span><span class="o">.</span><span class="n">efermi</span>
        <span class="n">cohp_data</span> <span class="o">=</span> <span class="n">cohp_file</span><span class="o">.</span><span class="n">cohp_data</span>
        <span class="n">energies</span> <span class="o">=</span> <span class="n">cohp_file</span><span class="o">.</span><span class="n">energies</span>

        <span class="c1"># Lobster shifts the energies so that the Fermi energy is at zero.</span>
        <span class="c1"># Shifting should be done by the plotter object though.</span>

        <span class="n">spins</span> <span class="o">=</span> <span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">,</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="k">if</span> <span class="n">cohp_file</span><span class="o">.</span><span class="n">is_spin_polarized</span> \
            <span class="k">else</span> <span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">fmt</span> <span class="o">==</span> <span class="s2">&quot;LOBSTER&quot;</span><span class="p">:</span>
            <span class="n">energies</span> <span class="o">+=</span> <span class="n">efermi</span>

        <span class="k">if</span> <span class="n">orb_res_cohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="c1"># If no total COHPs are present, calculate the total</span>
            <span class="c1"># COHPs from the single-orbital populations. Total COHPs</span>
            <span class="c1"># may not be present when the cohpgenerator keyword is used</span>
            <span class="c1"># in LOBSTER versions 2.2.0 and earlier.</span>
            <span class="c1"># TODO: Test this more extensively</span>
            <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">orb_res_cohp</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">cohp_file</span><span class="o">.</span><span class="n">cohp_data</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="c1"># print(label)</span>
                    <span class="n">cohp_data</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
                        <span class="n">sp</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orbs</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">][</span><span class="n">sp</span><span class="p">]</span> <span class="k">for</span> <span class="n">orbs</span> <span class="ow">in</span> <span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
                        <span class="k">for</span> <span class="n">sp</span> <span class="ow">in</span> <span class="n">spins</span><span class="p">}</span>
                <span class="k">if</span> <span class="n">cohp_file</span><span class="o">.</span><span class="n">cohp_data</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">cohp_data</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="p">{</span><span class="n">sp</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">orbs</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">][</span><span class="n">sp</span><span class="p">]</span>
                                     <span class="k">for</span> <span class="n">orbs</span> <span class="ow">in</span> <span class="n">orb_res_cohp</span><span class="p">[</span><span class="n">label</span><span class="p">]],</span>
                                    <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="k">for</span> <span class="n">sp</span> <span class="ow">in</span> <span class="n">spins</span><span class="p">}</span>

        <span class="k">if</span> <span class="n">fmt</span> <span class="o">==</span> <span class="s2">&quot;LMTO&quot;</span><span class="p">:</span>
            <span class="c1"># Calculate the average COHP for the LMTO file to be</span>
            <span class="c1"># consistent with LOBSTER output.</span>
            <span class="n">avg_data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;COHP&quot;</span><span class="p">:</span> <span class="p">{},</span> <span class="s2">&quot;ICOHP&quot;</span><span class="p">:</span> <span class="p">{}}</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">avg_data</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">spins</span><span class="p">:</span>
                    <span class="n">rows</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">cohp_data</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">spin</span><span class="p">]</span>
                                     <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">cohp_data</span><span class="p">])</span>
                    <span class="n">avg</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">average</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
                    <span class="c1"># LMTO COHPs have 5 significant figures</span>
                    <span class="n">avg_data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">spin</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">round_to_sigfigs</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
                                                        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">avg</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">float</span><span class="p">)})</span>
            <span class="n">avg_cohp</span> <span class="o">=</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span>
                            <span class="n">avg_data</span><span class="p">[</span><span class="s2">&quot;COHP&quot;</span><span class="p">],</span>
                            <span class="n">icohp</span><span class="o">=</span><span class="n">avg_data</span><span class="p">[</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">avg_cohp</span> <span class="o">=</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span>
                            <span class="n">cohp_data</span><span class="p">[</span><span class="s2">&quot;average&quot;</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">],</span>
                            <span class="n">icohp</span><span class="o">=</span><span class="n">cohp_data</span><span class="p">[</span><span class="s2">&quot;average&quot;</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">],</span>
                            <span class="n">are_coops</span><span class="o">=</span><span class="n">are_coops</span><span class="p">)</span>
            <span class="k">del</span> <span class="n">cohp_data</span><span class="p">[</span><span class="s2">&quot;average&quot;</span><span class="p">]</span>

        <span class="n">cohp_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">label</span><span class="p">:</span> <span class="n">Cohp</span><span class="p">(</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span>
                                 <span class="n">cohp_data</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="s2">&quot;COHP&quot;</span><span class="p">],</span>
                                 <span class="n">icohp</span><span class="o">=</span><span class="n">cohp_data</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="s2">&quot;ICOHP&quot;</span><span class="p">],</span>
                                 <span class="n">are_coops</span><span class="o">=</span><span class="n">are_coops</span><span class="p">)</span>
                     <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">cohp_data</span><span class="p">}</span>

        <span class="n">bond_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">label</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;length&quot;</span><span class="p">:</span> <span class="n">cohp_data</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="s2">&quot;length&quot;</span><span class="p">],</span>
                             <span class="s2">&quot;sites&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">structure</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="n">site</span><span class="p">]</span>
                                       <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">cohp_data</span><span class="p">[</span><span class="n">label</span><span class="p">][</span><span class="s2">&quot;sites&quot;</span><span class="p">]]}</span>
                     <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">cohp_data</span><span class="p">}</span>

        <span class="k">return</span> <span class="n">CompleteCohp</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">avg_cohp</span><span class="p">,</span> <span class="n">cohp_dict</span><span class="p">,</span> <span class="n">bonds</span><span class="o">=</span><span class="n">bond_dict</span><span class="p">,</span>
                            <span class="n">are_coops</span><span class="o">=</span><span class="n">are_coops</span><span class="p">,</span> <span class="n">orb_res_cohp</span><span class="o">=</span><span class="n">orb_res_cohp</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="IcohpValue"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.IcohpValue">[docs]</a><span class="k">class</span> <span class="nc">IcohpValue</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class to store information on an ICOHP or ICOOP value</span>

<span class="sd">    .. attribute:: num_bonds</span>
<span class="sd">            number of bonds used for the average cohp (relevant for Lobster versions &lt;3.0) (int)</span>

<span class="sd">    .. attribute:: are_coops</span>
<span class="sd">            Boolean to indicate whether ICOOP or not</span>

<span class="sd">    .. attribute:: icohp</span>
<span class="sd">            dict={Spin.up: icohpvalue for spin.up, Spin.down: icohpvalue for spin.down}</span>

<span class="sd">    .. attribute:: summed_icohp:</span>
<span class="sd">            sum of icohp/icoop of both spin channels</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">atom1</span><span class="p">,</span> <span class="n">atom2</span><span class="p">,</span> <span class="n">length</span><span class="p">,</span> <span class="n">translation</span><span class="p">,</span> <span class="n">num</span><span class="p">,</span> <span class="n">icohp</span><span class="p">,</span> <span class="n">are_coops</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            label: label for the icohp</span>
<span class="sd">            atom1: str of atom that is contributing to the bond</span>
<span class="sd">            atom2: str of second atom that is contributing to the bond</span>
<span class="sd">            length: float of bond lengths</span>
<span class="sd">            translation: translation list, e.g. [0,0,0]</span>
<span class="sd">            num: integer describing how often the bond exists</span>
<span class="sd">            icohp: dict={Spin.up: icohpvalue for spin.up, Spin.down: icohpvalue for spin.down}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_are_coops</span> <span class="o">=</span> <span class="n">are_coops</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_label</span> <span class="o">=</span> <span class="n">label</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_atom1</span> <span class="o">=</span> <span class="n">atom1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_atom2</span> <span class="o">=</span> <span class="n">atom2</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_length</span> <span class="o">=</span> <span class="n">length</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_translation</span> <span class="o">=</span> <span class="n">translation</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_num</span> <span class="o">=</span> <span class="n">num</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span> <span class="o">=</span> <span class="n">icohp</span>
        <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_is_spin_polarized</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_is_spin_polarized</span> <span class="o">=</span> <span class="kc">False</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_are_coops</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_spin_polarized</span><span class="p">:</span>
                <span class="k">return</span> <span class="p">(</span><span class="s2">&quot;ICOHP &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_label</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; between &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_atom1</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; and &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_atom2</span><span class="p">)</span> <span class="o">+</span>
                        <span class="s2">&quot; (&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_translation</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;): &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot; eV (Spin up) and &quot;</span> <span class="o">+</span>
                        <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot; eV (Spin down)&quot;</span><span class="p">)</span>
            <span class="k">return</span> <span class="p">(</span><span class="s2">&quot;ICOHP &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_label</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; between &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_atom1</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; and &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_atom2</span><span class="p">)</span> <span class="o">+</span>
                    <span class="s2">&quot; (&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_translation</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;): &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot; eV (Spin up)&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_spin_polarized</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">(</span><span class="s2">&quot;ICOOP &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_label</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; between &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_atom1</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; and &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_atom2</span><span class="p">)</span> <span class="o">+</span>
                    <span class="s2">&quot; (&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_translation</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;): &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot; (Spin up) and &quot;</span> <span class="o">+</span>
                    <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot; (Spin down)&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">(</span><span class="s2">&quot;ICOOP &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_label</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; between &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_atom1</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; and &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_atom2</span><span class="p">)</span> <span class="o">+</span>
                <span class="s2">&quot; (&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_translation</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;): &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot; (Spin up)&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">num_bonds</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        tells the number of bonds for which the ICOHP value is an average</span>
<span class="sd">        Returns:</span>
<span class="sd">            Int</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">are_coops</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        tells if ICOOPs or not</span>
<span class="sd">        Returns:</span>
<span class="sd">            Boolean</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_are_coops</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_spin_polarized</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        tells if spin polarized calculation or not</span>
<span class="sd">        Returns:</span>
<span class="sd">            Boolean</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_spin_polarized</span>

<div class="viewcode-block" id="IcohpValue.icohpvalue"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.IcohpValue.icohpvalue">[docs]</a>    <span class="k">def</span> <span class="nf">icohpvalue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            spin: Spin.up or Spin.down</span>
<span class="sd">        Returns:</span>
<span class="sd">            icohpvalue (float) corresponding to chosen spin</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span> <span class="ow">and</span> <span class="n">spin</span> <span class="o">==</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;The calculation was not performed with spin polarization&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">icohp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        dict with icohps for spinup and spindown</span>
<span class="sd">        Return:</span>
<span class="sd">            dict={Spin.up: icohpvalue for spin.up, Spin.down: icohpvalue for spin.down}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">summed_icohp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds ICOHPs of both spin channels for spin polarized compounds</span>
<span class="sd">        Returns:</span>
<span class="sd">             icohp value in eV</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_spin_polarized</span><span class="p">:</span>
            <span class="n">sum_icohp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">sum_icohp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">sum_icohp</span></div>


<div class="viewcode-block" id="IcohpCollection"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.IcohpCollection">[docs]</a><span class="k">class</span> <span class="nc">IcohpCollection</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class to store IcohpValues</span>

<span class="sd">    .. attribute:: are_coops</span>
<span class="sd">        Boolean to indicate whether ICOHPs or ICOOPs are stored</span>

<span class="sd">    .. attribute:: is_spin_polarized</span>
<span class="sd">        Boolean to indicate if the Lobster calculation was done spin polarized or not</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">list_labels</span><span class="p">,</span> <span class="n">list_atom1</span><span class="p">,</span> <span class="n">list_atom2</span><span class="p">,</span> <span class="n">list_length</span><span class="p">,</span>
                 <span class="n">list_translation</span><span class="p">,</span> <span class="n">list_num</span><span class="p">,</span> <span class="n">list_icohp</span><span class="p">,</span> <span class="n">is_spin_polarized</span><span class="p">,</span> <span class="n">are_coops</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            is_spin_polarized: Boolean to indicate if the Lobster calculation was done spin polarized or not Boolean to</span>
<span class="sd">                indicate if the Lobster calculation was done spin polarized or not</span>
<span class="sd">            are_coops: Boolean to indicate whether ICOHPs or ICOOPs are stored</span>
<span class="sd">            list_labels: list of labels for ICOHP/ICOOP values</span>
<span class="sd">            list_atom1: list of str of atomnames e.g. &quot;O1&quot;</span>
<span class="sd">            list_atom2: list of str of atomnames e.g. &quot;O1&quot;</span>
<span class="sd">            list_length: list of lengths of corresponding bonds in Angstrom</span>
<span class="sd">            list_translation: list of translation list, e.g. [0,0,0]</span>
<span class="sd">            list_num: list of equivalent bonds, usually 1 starting from Lobster 3.0.0</span>
<span class="sd">            list_icohp: list of dict={Spin.up: icohpvalue for spin.up, Spin.down: icohpvalue for spin.down}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_are_coops</span> <span class="o">=</span> <span class="n">are_coops</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_icohplist</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_is_spin_polarized</span> <span class="o">=</span> <span class="n">is_spin_polarized</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_list_labels</span> <span class="o">=</span> <span class="n">list_labels</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_list_atom1</span> <span class="o">=</span> <span class="n">list_atom1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_list_atom2</span> <span class="o">=</span> <span class="n">list_atom2</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_list_length</span> <span class="o">=</span> <span class="n">list_length</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_list_translation</span> <span class="o">=</span> <span class="n">list_translation</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_list_num</span> <span class="o">=</span> <span class="n">list_num</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_list_icohp</span> <span class="o">=</span> <span class="n">list_icohp</span>

        <span class="k">for</span> <span class="n">ilist</span><span class="p">,</span> <span class="n">listel</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">list_labels</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_icohplist</span><span class="p">[</span><span class="n">listel</span><span class="p">]</span> <span class="o">=</span> <span class="n">IcohpValue</span><span class="p">(</span><span class="n">listel</span><span class="p">,</span> <span class="n">list_atom1</span><span class="p">[</span><span class="n">ilist</span><span class="p">],</span> <span class="n">list_atom2</span><span class="p">[</span><span class="n">ilist</span><span class="p">],</span> <span class="n">list_length</span><span class="p">[</span><span class="n">ilist</span><span class="p">],</span>
                                                 <span class="n">list_translation</span><span class="p">[</span><span class="n">ilist</span><span class="p">],</span> <span class="n">list_num</span><span class="p">[</span><span class="n">ilist</span><span class="p">],</span> <span class="n">list_icohp</span><span class="p">[</span><span class="n">ilist</span><span class="p">])</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">joinstr</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohplist</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">joinstr</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">joinstr</span><span class="p">)</span>

<div class="viewcode-block" id="IcohpCollection.get_icohp_by_label"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.IcohpCollection.get_icohp_by_label">[docs]</a>    <span class="k">def</span> <span class="nf">get_icohp_by_label</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">summed_spin_channels</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        get an icohp value for a certain bond as indicated by the label (bond labels starting by &quot;1&quot; as in</span>
<span class="sd">        ICOHPLIST/ICOOPLIST)</span>

<span class="sd">        Args:</span>
<span class="sd">            label: label in str format (usually the bond number in Icohplist.lobster/Icooplist.lobster</span>
<span class="sd">            summed_spin_channels: Boolean to indicate whether the ICOHPs/ICOOPs of both spin channels should be summed</span>
<span class="sd">            spin: if summed_spin_channels is equal to False, this spin indicates which spin channel should be returned</span>

<span class="sd">        Returns:</span>
<span class="sd">            float describing ICOHP/ICOOP value</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">icohp_here</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohplist</span><span class="p">[</span><span class="n">label</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">icohp_here</span><span class="o">.</span><span class="n">_is_spin_polarized</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">summed_spin_channels</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">icohp_here</span><span class="o">.</span><span class="n">summed_icohp</span>
            <span class="k">return</span> <span class="n">icohp_here</span><span class="o">.</span><span class="n">icohpvalue</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">icohp_here</span><span class="o">.</span><span class="n">icohpvalue</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span></div>

<div class="viewcode-block" id="IcohpCollection.get_summed_icohp_by_label_list"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.IcohpCollection.get_summed_icohp_by_label_list">[docs]</a>    <span class="k">def</span> <span class="nf">get_summed_icohp_by_label_list</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label_list</span><span class="p">,</span> <span class="n">divisor</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">summed_spin_channels</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        get the sum of several ICOHP values that are indicated by a list of labels (labels of the bonds are the same as</span>
<span class="sd">        in ICOHPLIST/ICOOPLIST)</span>

<span class="sd">        Args:</span>
<span class="sd">            label_list: list of labels of the ICOHPs/ICOOPs that should be summed</span>
<span class="sd">            divisor: is used to divide the sum</span>
<span class="sd">            summed_spin_channels: Boolean to indicate whether the ICOHPs/ICOOPs of both spin channels should be summed</span>
<span class="sd">            spin: if summed_spin_channels is equal to False, this spin indicates which spin channel should be returned</span>

<span class="sd">        Returns:</span>
<span class="sd">             float that is a sum of all ICOHPs/ICOOPs as indicated with label_list</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sum_icohp</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">label_list</span><span class="p">:</span>
            <span class="n">icohp_here</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohplist</span><span class="p">[</span><span class="n">label</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">icohp_here</span><span class="o">.</span><span class="n">num_bonds</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;One of the ICOHP values is an average over bonds. This is currently not considered.&quot;</span><span class="p">)</span>
            <span class="c1"># prints warning if num_bonds is not equal to 1</span>
            <span class="k">if</span> <span class="n">icohp_here</span><span class="o">.</span><span class="n">_is_spin_polarized</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">summed_spin_channels</span><span class="p">:</span>
                    <span class="n">sum_icohp</span> <span class="o">=</span> <span class="n">sum_icohp</span> <span class="o">+</span> <span class="n">icohp_here</span><span class="o">.</span><span class="n">summed_icohp</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">sum_icohp</span> <span class="o">=</span> <span class="n">sum_icohp</span> <span class="o">+</span> <span class="n">icohp_here</span><span class="o">.</span><span class="n">icohpvalue</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">sum_icohp</span> <span class="o">=</span> <span class="n">sum_icohp</span> <span class="o">+</span> <span class="n">icohp_here</span><span class="o">.</span><span class="n">icohpvalue</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">sum_icohp</span> <span class="o">/</span> <span class="n">divisor</span></div>

<div class="viewcode-block" id="IcohpCollection.get_icohp_dict_by_bondlengths"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.IcohpCollection.get_icohp_dict_by_bondlengths">[docs]</a>    <span class="k">def</span> <span class="nf">get_icohp_dict_by_bondlengths</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">minbondlength</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">maxbondlength</span><span class="o">=</span><span class="mf">8.0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        get a dict of IcohpValues corresponding to certaind bond lengths</span>
<span class="sd">        Args:</span>
<span class="sd">            minbondlength: defines the minimum of the bond lengths of the bonds</span>
<span class="sd">            maxbondlength: defines the maximum of the bond lengths of the bonds</span>
<span class="sd">        Returns:</span>
<span class="sd">             dict of IcohpValues, the keys correspond to the values from the initial list_labels</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">newicohp_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohplist</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">_length</span> <span class="o">&gt;=</span> <span class="n">minbondlength</span> <span class="ow">and</span> <span class="n">value</span><span class="o">.</span><span class="n">_length</span> <span class="o">&lt;=</span> <span class="n">maxbondlength</span><span class="p">:</span>
                <span class="n">newicohp_dict</span><span class="p">[</span><span class="n">value</span><span class="o">.</span><span class="n">_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
        <span class="k">return</span> <span class="n">newicohp_dict</span></div>

<div class="viewcode-block" id="IcohpCollection.get_icohp_dict_of_site"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.IcohpCollection.get_icohp_dict_of_site">[docs]</a>    <span class="k">def</span> <span class="nf">get_icohp_dict_of_site</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">site</span><span class="p">,</span> <span class="n">minsummedicohp</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">maxsummedicohp</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">minbondlength</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span>
                               <span class="n">maxbondlength</span><span class="o">=</span><span class="mf">8.0</span><span class="p">,</span> <span class="n">only_bonds_to</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        get a dict of IcohpValue for a certain site (indicated by integer)</span>
<span class="sd">        Args:</span>
<span class="sd">            site: integer describing the site of interest, order as in Icohplist.lobster/Icooplist.lobster, starts at 0</span>
<span class="sd">            minsummedicohp: float, minimal icohp/icoop of the bonds that are considered. It is the summed ICOHP value</span>
<span class="sd">                from both spin channels for spin polarized cases</span>
<span class="sd">            maxsummedicohp: float, maximal icohp/icoop of the bonds that are considered. It is the summed ICOHP value</span>
<span class="sd">                from both spin channels for spin polarized cases</span>
<span class="sd">            minbondlength: float, defines the minimum of the bond lengths of the bonds</span>
<span class="sd">            maxbondlength: float, defines the maximum of the bond lengths of the bonds</span>
<span class="sd">            only_bonds_to: list of strings describing the bonding partners that are allowed, e.g. [&#39;O&#39;]</span>
<span class="sd">        Returns:</span>
<span class="sd">             dict of IcohpValues, the keys correspond to the values from the initial list_labels</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">newicohp_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohplist</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">atomnumber1</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;(\d+)&#39;</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">_atom1</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span> <span class="o">-</span> <span class="mi">1</span>
            <span class="n">atomnumber2</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;(\d+)&#39;</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">_atom2</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span> <span class="o">-</span> <span class="mi">1</span>
            <span class="k">if</span> <span class="n">site</span> <span class="ow">in</span> <span class="p">(</span><span class="n">atomnumber1</span><span class="p">,</span> <span class="n">atomnumber2</span><span class="p">):</span>
                <span class="c1"># manipulate order of atoms so that searched one is always atom1</span>
                <span class="k">if</span> <span class="n">site</span> <span class="o">==</span> <span class="n">atomnumber2</span><span class="p">:</span>
                    <span class="n">save</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">_atom1</span>
                    <span class="n">value</span><span class="o">.</span><span class="n">_atom1</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">_atom2</span>
                    <span class="n">value</span><span class="o">.</span><span class="n">_atom2</span> <span class="o">=</span> <span class="n">save</span>

                <span class="k">if</span> <span class="n">only_bonds_to</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">second_test</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">second_test</span> <span class="o">=</span> <span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;(\d+)&#39;</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">_atom2</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="n">only_bonds_to</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">_length</span> <span class="o">&gt;=</span> <span class="n">minbondlength</span> <span class="ow">and</span> <span class="n">value</span><span class="o">.</span><span class="n">_length</span> <span class="o">&lt;=</span> <span class="n">maxbondlength</span> <span class="ow">and</span> <span class="n">second_test</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">minsummedicohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">summed_icohp</span> <span class="o">&gt;=</span> <span class="n">minsummedicohp</span><span class="p">:</span>
                            <span class="k">if</span> <span class="n">maxsummedicohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                                <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">summed_icohp</span> <span class="o">&lt;=</span> <span class="n">maxsummedicohp</span><span class="p">:</span>
                                    <span class="n">newicohp_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">newicohp_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">maxsummedicohp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                            <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">summed_icohp</span> <span class="o">&lt;=</span> <span class="n">maxsummedicohp</span><span class="p">:</span>
                                <span class="n">newicohp_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">newicohp_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

        <span class="k">return</span> <span class="n">newicohp_dict</span></div>

<div class="viewcode-block" id="IcohpCollection.extremum_icohpvalue"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.cohp.html#pymatgen.electronic_structure.cohp.IcohpCollection.extremum_icohpvalue">[docs]</a>    <span class="k">def</span> <span class="nf">extremum_icohpvalue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">summed_spin_channels</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        get ICOHP/ICOOP of strongest bond</span>
<span class="sd">        Args:</span>
<span class="sd">            summed_spin_channels: Boolean to indicate whether the ICOHPs/ICOOPs of both spin channels should be summed</span>

<span class="sd">            spin: if summed_spin_channels is equal to False, this spin indicates which spin channel should be returned</span>
<span class="sd">        Returns:</span>
<span class="sd">            lowest ICOHP/largest ICOOP value (i.e. ICOHP/ICOOP value of strongest bond)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_are_coops</span><span class="p">:</span>
            <span class="n">extremum</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">float_info</span><span class="o">.</span><span class="n">max</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">extremum</span> <span class="o">=</span> <span class="o">-</span><span class="n">sys</span><span class="o">.</span><span class="n">float_info</span><span class="o">.</span><span class="n">max</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_spin_polarized</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">spin</span> <span class="o">==</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;This spin channel does not exist. I am switching to Spin.up&quot;</span><span class="p">)</span>
            <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="o">.</span><span class="n">up</span>

        <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_icohplist</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">value</span><span class="o">.</span><span class="n">is_spin_polarized</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">summed_spin_channels</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_are_coops</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">icohpvalue</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">extremum</span><span class="p">:</span>
                        <span class="n">extremum</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">icohpvalue</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span>
                        <span class="c1"># print(extremum)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">icohpvalue</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">extremum</span><span class="p">:</span>
                        <span class="n">extremum</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">icohpvalue</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span>
                        <span class="c1"># print(extremum)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_are_coops</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">summed_icohp</span> <span class="o">&lt;</span> <span class="n">extremum</span><span class="p">:</span>
                        <span class="n">extremum</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">summed_icohp</span>
                        <span class="c1"># print(extremum)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">summed_icohp</span> <span class="o">&gt;</span> <span class="n">extremum</span><span class="p">:</span>
                        <span class="n">extremum</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">summed_icohp</span>
                        <span class="c1"># print(extremum)</span>
        <span class="k">return</span> <span class="n">extremum</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_spin_polarized</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Whether it is spin polarized.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_spin_polarized</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">are_coops</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Whether this is coops.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_are_coops</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.electronic_structure.cohp</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>